<template>
	<view>
		<u-popup round='30' :show="showPopup">
			<view class="select_item pd_lr10" :style="{height:popupHeight+'px'}">
				<view class="select_item_top">
					<view class="select_item_top_l" v-if="updateNoneImg">
						<image :src="
						commonityItem && 
						commonityItem.picture ?
						uploadImgUrl +  commonityItem.picture : 
						computedMorentu"></image>
					</view>
					<view class="select_item_top_c">
						<view class="select_item_top_c_t mtb10 texttowShow">
							{{commonityItem && commonityItem.name ? commonityItem.name : ''}}
						</view>
						<view class="select_item_top_c_b">
							<text class="money">￥{{
								computedSkuPrice
							}}</text>/
							<!-- {{commonityItem.defaultSKU &&
								commonityItem.defaultSKU.unitInfo && 
								commonityItem.defaultSKU.unitInfo.name &&
								commonityItem.defaultSKU.specsOptionInfo && 
								commonityItem.defaultSKU.specsOptionInfo.length ? 
								commonityItem.defaultSKU.unitInfo.name + '/' + 
								commonityItem.defaultSKU.specsOptionInfo.map(it=>it.optionName).join('-') :
								commonityItem.defaultSKU &&
									commonityItem.defaultSKU.unitInfo && 
									commonityItem.defaultSKU.unitInfo.name ?
								commonityItem.defaultSKU.unitInfo.name : ''}} -->
							<!-- {{
								commonityItem.defaultSKU &&
									commonityItem.defaultSKU.unitInfo && 
									commonityItem.defaultSKU.unitInfo.name ?
								commonityItem.defaultSKU.unitInfo.name : ''}} -->
								{{computedSkuUnit}}
							<text v-if="commonityItem.stockMark == 2"
								style="margin-left: 20rpx;">库存:{{computedStock && Utils.formatToFixed(computedStock,'number') || 0}}</text>
							<text v-if="commonityItem.stockMark == 3"
								style="margin-left: 20rpx;">库存:{{commonityItem.defaultSKU && commonityItem.defaultSKU.stockNum  && commonityItem.defaultSKU.stockNum > 0 ? '有'  : '无'}}</text>
							<!-- <text class=" ml5">库存:14241</text> -->
						</view>
					</view>
					<view @click='close' class="select_item_top_r mt10">
						<image :src="xcxImgUrl && xcxImgUrl+'close.svg'"></image>
					</view>
				</view>

				<view class="select_item_list">
					<!-- <view class="select_item_unit">
						<view class="select_item_unit_item select_item_unit_item_active">
							个
						</view>
						<view class="select_item_unit_item">
							件
						</view>
						<view class="select_item_unit_item">
							箱
						</view>
						<view class="select_item_unit_item">
							车
						</view>
						<view class="select_item_unit_item">
							个
						</view>
						<view class="select_item_unit_item">
							个
						</view>
					</view> -->
					<template v-if="commonityItem && commonityItem.isUnits == 1">
						<view class="select_item_options mtb10">
							<view class="select_item_options_title mb10">
								单位
							</view>
							<view class="select_item_options_item">
								<view v-for="(item,index) in commonityItem.skuInfo" :key="index"
									@click="tapUnitsCommonity(item,index)" class="select_item_options_item_l"
									:class="unitsActive == index ? 'select_item_options_item_l_active' : ''">
									{{
									item && 
									item.unitInfo && 
									item.unitInfo.name ? 
									item.unitInfo.name : ''
									}}
								</view>
							</view>
						</view>
					</template>
					<template v-if="commonityItem && commonityItem.isSpecs == 1">
						<view v-for="(item,index) in commonityItem.specses" :key="index"
							class="select_item_options mtb10">
							<view class="select_item_options_title mb10">
								{{item.specsName}}
							</view>
							<view class="select_item_options_item">
								<view v-for="(it,inx) in item.list" :key="inx"
									@click="tapSpecsCommonity(item,it,index,inx)" class="select_item_options_item_l "
									:style="{background:heightLight(it) ? '' : '#ccc',pointerEvents:heightLight(it) ? '' : 'none'}"
									:class="it && it.currentObj.checked ? 'select_item_options_item_l_active' : ''">
									{{it && it.currentObj.optionName}}
									<!-- {{heightLight(it)}} -->
								</view>
								<!-- :class="item.specsesActive == inx ? 'select_item_options_item_l_active' : ''" -->
							</view>
						</view>
					</template>
				</view>

				<view class="select_item_num">
					<view class="select_item_num_l">
						购买数量<text>（最多购买{{morethanBuy || 0}}件）</text>
					</view>
					<view class="" style="width:180rpx;">
						<u-number-box>
							<view slot="minus" @click="delNum" class="minus" :style="{background:it.qty <= 1 ? 'rgba(255, 0, 0, 0.5)' : 'rgba(255, 0, 0, 1)'}">
								<u-icon name="minus" size="12" color="#FFFFFF"></u-icon>
							</view>
							<u-input border='none' style="width: 50px;text-align: center;padding:16rpx" class="input"
								inputAlign='center' slot="input" type='number' :value='value' @focus="focusNum"
								@input='inputNum'
								@blur='blurNum'>
							</u-input>
							<!-- <text slot="input"
						 		style="width: 50px;text-align: center;"
						 		class="input"></text> -->
							<view slot="plus" @click="addNum" class="plus">
								<u-icon name="plus" color="#FFFFFF" size="12"></u-icon>
							</view>
						</u-number-box>
					</view>
				</view>

				<view v-if="addOrgoumai==1" @click="addCard" class="btn">
					<newBtn bgColor="#333" color="#FFF" name="加入购物车"></newBtn>
				</view>
				<view v-if="addOrgoumai==2" @click="addCard" class="btn">
					<newBtn bgColor="#EC4141" color="#FFF" name="立即购买"></newBtn>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import newBtn from '@/components/newBtn/newBtn.vue'
	import {
		uploadImgUrl
	} from '@/utils/request.js'
	import {
		addMallShoppingCart,getCatCount
	} from '@/api/global.js'
	export default {
		name: "addCardPopup",
		props: {
			updateNoneImg:{
				type:Boolean,
				default:false
			},
			commonityItem: {
				type: Object,
				default: () => {}
			},	
			itemObj:{
				type: Object,
				default: () => {}
			},
			addOrgoumai: {
				type: Number,
				default: 1
			}	
		},
		inject: ['resetList'],
		computed: {
			computedStock() {
				console.log(this.commonityItem ,'this.commonityItem');
				try{
					if (this.commonityItem && this.commonityItem.isSpecs == 1) {
						if (this.commonityItem.skuInfo && this
							.commonityItem.skuInfo.every(v => v.specsOptionInfo.length == 1)) { // 单自由项
							this.morethanBuy = this.commonityItem.skuInfo && this.commonityItem.skuInfo[this.firstIndex].stockNum * 1 > 0 ? this
								.commonityItem.skuInfo[this.firstIndex].stockNum : 0;
							this.value = this.commonityItem.skuInfo && this.commonityItem.skuInfo[this.firstIndex].stockNum * 1 > 0 ? 1 : 0;
							return this.commonityItem.skuInfo[this.firstIndex].stockNum;
						} else if (this.commonityItem.skuInfo && this
							.commonityItem.skuInfo.every(v => v.specsOptionInfo.length == 2)) { //多自由项
							if (this.firstFreeName && this.lastFreeName) {
								let result = this.commonityItem.skuInfo.filter(v => v.specsOptionInfo[0].optionName == this
									.firstFreeName && v
									.specsOptionInfo[1].optionName == this.lastFreeName)
								this.commonityItem.defaultSKU = result[0];
								this.morethanBuy = result[0].stockNum * 1 > 0 ? result[0].stockNum : 0;
								this.value = result[0].stockNum * 1 > 0 ? 1 : 0;
								return result[0].stockNum;
							}
						}
					} else {
						this.morethanBuy = this.commonityItem.skuInfo && this.commonityItem.skuInfo[this.unitsActive].stockNum * 1 > 0 ? this.commonityItem
							.skuInfo[this.unitsActive].stockNum : 0;
						this.value = this.commonityItem.skuInfo && this.commonityItem.skuInfo[this.unitsActive].stockNum * 1 > 0 ? 1 : 0;
						return this.commonityItem.skuInfo[this.unitsActive].stockNum;
					}
				}catch(e){
					//TODO handle the exception
				}
			},
				
			computedSkuUnit(){
				// console.log(this.commonityItem,'this.commonityItem');
				return  this.commonityItem.defaultSKU && this.commonityItem.defaultSKU.unitInfo.name 
			},
			computedSkuPrice() {
				if (this.commonityItem && this.commonityItem.isSpecs == 1) {
					if (this.commonityItem.skuInfo && this
						.commonityItem.skuInfo.every(v => v.specsOptionInfo.length == 1)) {
						return this.commonityItem && this.commonityItem.skuInfo &&
							this.commonityItem.skuInfo.length &&
							this.commonityItem.skuInfo[this.firstIndex]['skuPriceInfo'] &&
							this.commonityItem.skuInfo[this.firstIndex]['skuPriceInfo'].length 
							&&this.commonityItem.skuInfo[this.firstIndex]['priceTrackingInfo'] 
							&&this.commonityItem.skuInfo[this.firstIndex]['priceTrackingInfo'].price
							?
							this.Utils.formatToFixed(this.commonityItem.skuInfo[this.firstIndex]['priceTrackingInfo'].price,
								'price') :
							this.Utils.formatToFixed(this.commonityItem.skuInfo[this.firstIndex]['skuPriceInfo'][0].price,
								'price')
					} else if (this.commonityItem.skuInfo && this
						.commonityItem.skuInfo.every(v => v.specsOptionInfo.length == 2)) {
						let i = this.commonityItem.skuInfo.findIndex(v => {
							return v.specsOptionInfo[0].optionName == this.firstFreeName && v
								.specsOptionInfo[1].optionName == this.lastFreeName
						});
						return this.commonityItem && this.commonityItem.skuInfo &&
							this.commonityItem.skuInfo.length &&
							this.commonityItem.skuInfo[i < 0 ? 0 : i]['skuPriceInfo'] &&
							this.commonityItem.skuInfo[i < 0 ? 0 : i]['skuPriceInfo'].length &&
							this.commonityItem.skuInfo[i < 0 ? 0 : i]['skuPriceInfo'][0].price 
							&&this.commonityItem.skuInfo[i < 0 ? 0 : i]['priceTrackingInfo'] 
							?
							this.Utils.formatToFixed(this.commonityItem.skuInfo[i < 0 ? 0 : i]['priceTrackingInfo'].price,
								'price') :
							this.Utils.formatToFixed(this.commonityItem.skuInfo[i < 0 ? 0 : i]['skuPriceInfo'][0].price,
								'price') 
					}
				} else {
					
					return this.commonityItem.defaultSKU &&
						this.commonityItem.defaultSKU.skuPriceInfo &&
						this.commonityItem.defaultSKU.skuPriceInfo.length &&
						this.commonityItem.defaultSKU.skuPriceInfo[0].price &&
						this.commonityItem.defaultSKU.priceTrackingInfo
						?
						this.Utils.formatToFixed(this.commonityItem.defaultSKU.priceTrackingInfo.price, 'price') : this.Utils.formatToFixed(this.commonityItem.defaultSKU?.skuPriceInfo[0].price, 'price')
				}
			},
			//默认图
			computedMorentu() {
				return this.$store?.state?.morentu
			},
			heightLight() {
				let data = this.commonityItem.specses;
				let arr1 = this.firstFreeArr;
				let currentFirstFree = this.firstFreeName;
				return (item) => {
					// console.log(this.firstFreeArr)
					let all = item.all;
					let all1 = currentFirstFree ? all.filter(v => v.split('-')[0] == currentFirstFree).map(v => v
						.split('-')[1]) : this.lastFreeArr;
					return arr1?.includes(item.currentObj.optionName) || all1?.includes(item.currentObj.optionName) ?
						true : false;
				}
			}

		},
		components: {
			newBtn
		},
		watch: {
			commonityItem(val) {
				if (this.commonityItem && this.commonityItem.specses && this.commonityItem.specses) {
					this.firstFreeArr = this.commonityItem.specses[0].list?.map(v => v.currentObj.optionName);
					this.oldFirstFreeArr = this.commonityItem.specses[0].list?.map(v => v.currentObj.optionName);
					this.lastFreeArr = this.commonityItem.specses.length == 2 ?
						this.commonityItem.specses[1].list?.map(v => v.currentObj.optionName) : [];
					this.oldLastFreeArr = this.commonityItem.specses.length == 2 ?
						this.commonityItem.specses[1].list?.map(v => v.currentObj.optionName) : [];
				}
			}
		},
		options: {
			styleIsolation: 'shared', // 解除样式隔离
		},
		data() {
			return {
			   oldValue:'',
				timer:null,
				keyBoardHeight:0,
				firstIndex: 0,
				morethanBuy: 0,
				stockCount: 0,
				firstFreeName: ``,
				lastFreeName: ``,
				firstFreeArr: [],
				oldFirstFreeArr: [],
				lastFreeArr: [],
				oldLastFreeArr: [],
				showPopup: false, //购物车选择列表
				value: 1,
				uploadImgUrl,
				unitsActive: 0, //点击选择单位的下标
				commonityDetailsId: '', //选择单位对应skuid 传给添加购物车
				specsesText: [], //存储选择的多自由项的拼接项
				popupHeight: 200,
			};
		},
		mounted() {
			let bottomHeight = uni.getMenuButtonBoundingClientRect().bottom; //获取胶囊底部位置 
			let systemHeight = uni.getSystemInfoSync() && uni.getSystemInfoSync().screenHeight; //系统高度
			this.popupHeight = systemHeight * 0.75 - bottomHeight;
		},
		onHide() {
		 this.$emit('keep',this.value)	
		},
		methods: {
				// 获取购物车数量
						async getCatToally(){
							const {data} = await getCatCount({
								type:1
							})
						
							uni.setTabBarBadge({
							  index: 2,
							  text: data.info.toString()
							})
							
						},
			//点击单位选择
			tapUnitsCommonity(item, index) {
				console.log(item);
				this.unitsActive = index;
				//取单位的skuId 用于保存
				this.commonityDetailsId = item.detailId;

				//分开赋值
				//取单位的价格
				// this.commonityItem.defaultSKU.skuPriceInfo[0].price = item?.skuPriceInfo?.[0]?.price || 0 //页面展示
				// //取单位
				// this.commonityItem.defaultSKU.unitInfo = item?.unitInfo || ''
				// //取库存
				// this.commonityItem.defaultSKU.stockNum = item?.stockNum || 0

				//整个赋值
				this.commonityItem.defaultSKU = item

				//如果数量大于库存 重置数量为当前库存
				if (this.value > this.commonityItem.defaultSKU.stockNum) {
					this.value = this.commonityItem.defaultSKU.stockNum
				}
			},
			//点击自由项选择
			tapSpecsCommonity(item, it, index, inx) {
				this.firstIndex = inx;
				let two = it.name.split('-')[1];
				let all = it.all;
				let filter = all.filter(v => v.split('-')[1] == two);
				// this.firstFree = it.name.split('-')[0];
				item.specsesActive = inx;
				item.list.forEach((v, i) => {
					if (i == inx) {
						v.currentObj.checked = !v.currentObj.checked;
						if (v.currentObj.checked) {
							this.firstFreeArr = filter.map(v => v.split('-')[0]);
						} else {
							this.firstFreeArr = this.oldFirstFreeArr;
						}
					} else {
						v.currentObj.checked = false;
					}
				})
				if (index == 0) {
					this.firstFreeName = it.currentObj.optionName;
					this.commonityDetailsId = it.currentObj.detailId;
					if (!it.currentObj.checked) {
						this.commonityItem.specses[1].list.forEach(v => {
							v.currentObj.checked = false;
							this.lastFreeArr = this.oldLastFreeArr;
							this.firstFreeName = ``;
						})
					}
				} else if (index == 1) {
					this.lastFreeName = it.currentObj.optionName;
					this.commonityDetailsId = it.currentObj.detailId;
					if (!it.currentObj.checked) {
						this.lastFreeName = ``;
					}
				}
				// console.log(this.commonityDetailsId)
				// console.log(item.list, 1)
				//如果没有 循环多自由项数组 默认先取第一个
				if (!this.specsesText.length) {
					this.commonityItem.specses.forEach((item, index) => {
						//拼接每个项的第一项
						this.specsesText.splice(index, 1, item?.cses?.[0]?.optionName);
					})
				}

				//先删除当前的项
				if (this.specsesText.length) {
					this.specsesText.splice(index, 1)
				}

				//存放选择的项
				this.specsesText.splice(index, 0, it.optionName)
				// console.log(this.specsesText);

				//循环所有的多自由项 先拼接里面的项 然后和选择的拼接的项做对比
				this.commonityItem.skuInfo = this.commonityItem.skuInfo.map((item, index) => {
					return {
						...item,
						specsText: item.specsOptionInfo.map(it => it.optionName).join('/')
					}
				})
				// console.log(this.commonityItem.skuInfo);




				//如果选择的项和拼接的项相等
				// this.commonityItem.skuInfo.forEach((item, index) => {
				// 	// if (this.specsesText.join('/') == item.specsText) {
				// 	if (this.firstFreeName && this.lastFreeName) {
				// 		console.log(this.commonityDetailsId);
				// 		//赋值展示操作
				// 		//取多自由项的skuId 用于保存添加购物车
				// 		// this.commonityDetailsId = item.detailId;

				// 		// 分开赋值
				// 		// //取多自由项的价格
				// 		// this.commonityItem.defaultSKU.skuPriceInfo[0].price = item?.skuPriceInfo?.[0]?.price || 0 //页面展示
				// 		// //取多自由项
				// 		// this.commonityItem.defaultSKU.unitInfo = item?.unitInfo || ''
				// 		// //取库存
				// 		// this.commonityItem.defaultSKU.stockNum = item?.stockNum || 0

				// 		//整个skuInfo赋值
				// 		this.commonityItem.defaultSKU = item

				// 		//如果数量大于库存 重置数量为当前库存
				// 		if (this.value > this.commonityItem.defaultSKU.stockNum) {
				// 			this.value = this.commonityItem.defaultSKU.stockNum
				// 		}
				// 	}
				// })


			},
			//点击加号添加数量
			addNum() {
				++this.value
				//如果当前数量大于当前库存数量 不可继续添加
				if (this.value > this.commonityItem.defaultSKU.stockNum || this.commonityItem.defaultSKU.stockNum < 0) {
					this.value = this.commonityItem.defaultSKU.stockNum <= 0 ? 0 : this.commonityItem.defaultSKU.stockNum
					this.Utils.toast(`当前数量已大于库存数量`)
					return
				}
			},
			//点击减号减少数量
			delNum() {
				--this.value
				if (this.value <= 0) {
					this.value = 0
				}
			},
				
			inputNum(e){
				this.value = e
				clearTimeout(this.timer);
				this.timer = setTimeout(() => {
					if (this.value > this.computedStock) {
						this.Utils.toast(`当前数量已大于库存数量`)
						setTimeout(() => {
							this.value = this.computedStock <= 0 ? 0 : this.computedStock;
						},500)
					}
				}, 600)
				
			},
			focusNum(e) {
				this.keyBoardHeight = e.detail && e.detail.height;
				let bottomHeight = uni.getMenuButtonBoundingClientRect().bottom; //获取胶囊底部位置
				let systemHeight = uni.getSystemInfoSync() && uni.getSystemInfoSync().screenHeight; //系统高度
				this.popupHeight = systemHeight * 0.7 - bottomHeight + e.detail.height;
			},
			//数量输入框失去焦点
			blurNum() {
				let bottomHeight = uni.getMenuButtonBoundingClientRect().bottom; //获取胶囊底部位置
				let systemHeight = uni.getSystemInfoSync() && uni.getSystemInfoSync().screenHeight; //系统高度
				this.popupHeight = systemHeight * 0.7 - bottomHeight * 0.4 + this.keyBoardHeight;
				if (this.value <= 0) {
					this.value = 0
				}
				if (this.value && this.value.startsWith('0') && !this.value.includes('.')) {
					this.value = this.value.slice(1, this.value.length)
				}
				if (this.value > this.computedStock) {
					this.Utils.toast(`当前数量已大于库存数量`)
					this.value = this.computedStock <= 0 ? 0 : this.computedStock;
				}
				// item.num = parseInt(item.num)
			},
			//点击加入购物车
			async addCard() {
				// if(!this.commonityItem?.defaultSKU?.skuPriceInfo?.[0]?.price){
				// 	this.Utils.toast(`当前商品暂无价格，无法添加购物车`);
				// 	return;
				// }
				//如果是多单位 或者 多单位且一个自由项
				if ((this.commonityItem?.isUnits == 1 && this.commonityItem?.isSpecs == 2 && this.commonityDetailsId ==
						'') ||
					(this.commonityItem?.isUnits == 1 && this.commonityItem?.isSpecs == 1 && this.commonityDetailsId ==
						'')) {
					this.commonityDetailsId = this?.commonityItem?.skuInfo?.[0]?.detailId || ''
				}
				//如果是多自由项 初始化默认加载第一个多自由项
				if (this.commonityItem.isSpecs == 1 && this.commonityItem?.isUnits == 2) {
					//循环多自由项数组 
					this.commonityItem.specses.forEach((item, index) => {
						//拼接每个项的第一项
						this.specsesText.splice(index, 1, item?.cses?.[0]?.optionName);
					})
					if (this.commonityItem.specses && this.commonityItem.specses.length == 2 && this.commonityItem
						.specses[1].list.length) {
						if (!(this.firstFreeName && this.lastFreeName)) {
							this.Utils.toast(`多自由项必选`);
							return;
						}
					}

					if (this.firstFreeName && this.lastFreeName) {
						let result = this.commonityItem.skuInfo.filter(v => v.specsOptionInfo[0].optionName == this
							.firstFreeName && v
							.specsOptionInfo[1].optionName == this.lastFreeName)
						this.commonityDetailsId = result[0].detailId;
						
					}
					//循环所有的多自由项 先拼接里面的项 然后和选择的拼接的项做对比
					this.commonityItem.skuInfo = this.commonityItem.skuInfo.map((item, index) => {
						return {
							...item,
							specsText: item.specsOptionInfo.map(it => it.optionName).join('/')
						}
					})
				;

					//如果选择的项和拼接的项相等
					// this.commonityItem.skuInfo.forEach((item, index) => {
					// 	if (this.specsesText.join('/') == item.specsText) {
					// 		console.log(item);
					// 		//赋值展示操作
					// 		//取多自由项的skuId 用于保存添加购物车
					// 		this.commonityDetailsId = item.detailId;

					// 		// 分开赋值
					// 		// //取多自由项的价格
					// 		// this.commonityItem.defaultSKU.skuPriceInfo[0].price = item?.skuPriceInfo?.[0]?.price || 0 //页面展示
					// 		// //取多自由项
					// 		// this.commonityItem.defaultSKU.unitInfo = item?.unitInfo || ''
					// 		// //取库存
					// 		// this.commonityItem.defaultSKU.stockNum = item?.stockNum || 0

					// 		//整个skuInfo赋值
					// 		this.commonityItem.defaultSKU = item
					// 	}
					// })

				}

				//判断是否有数量
				if (this.value == 0) {
					this.Utils.toast(`请选购数量`)
					return
				}

				//判断当前商品是否有单价
				// if (this?.commonityItem?.defaultSKU?.skuPriceInfo?.[0]?.price == 0) {
				// 	this.Utils.toast(`当前商品暂无价格，无法添加购物车`)
				// 	return
				// }

				// 如果加入购物车 调接口
				if (this.addOrgoumai == 1) {
					//调用接口
					let res = await addMallShoppingCart({
						type: 1, //类型[1：普通购物车 2：商品满减购物车 3：商品满赠购物车]
						commodityId: this.commonityItem.commodityId || '', //商品SPUid
						commodityDetailId: this.commonityDetailsId || '', //商品SKUid
						qty: this.value || 0,
						price: this.computedSkuPrice || 0,
						money: this.Utils.formatToFixed(this.value * this.computedSkuPrice || 0, 'money') || 0,
						summary: '',
					})
					if (res.code == 2000) {
						this.Utils.toast(`已添加购物车`)
					   this.$store.commit('updateCount', this.value)
						setTimeout(() => {
							this.close()
							this.$emit('publish');
							this.resetList()
							this.getCatToally()
							
						}, 200)
					} else {
						this.Utils.toast(`${res.msg}`)
					}
				}
				if (this.addOrgoumai == 2) { //立即购买

					//拼出订单详情需要的结构
					let arr = []
					arr.push({
						spuInfo: {
							picture: this.commonityItem?.picture || '', //头像
							name: this.commonityItem?.name || '',
						},
						children: [{
							skuChecked: true,
							skuInfo: this.commonityItem?.defaultSKU || {},
							// price: this.commonityItem?.defaultSKU?.skuPriceInfo?.[0]?.price || 0,
							price: this.computedSkuPrice || 0,
							commodityId: this.commonityItem?.defaultSKU?.commodityId || '',
							commodityDetailId: this.commonityItem?.defaultSKU?.detailId || '',
							qty: this.value,
							money: this.Utils.formatToFixed(this.value * this.computedSkuPrice,
								'money'),
							summary: '',
							branchId: this.$store.state.branchId, //商品详情对象中没有 取全局
							accountId: this.commonityItem?.defaultSKU?.accountId || '',
							bussinessId: this.commonityItem?.defaultSKU?.bussinessId || '',
						}]
					})


					//先把购物车商品添加vuex =在结算页面回显
					this.$store.commit('cardCommonity', arr)

					uni.navigateTo({
						url: '/page_public/confirmOrder?type=2'
					})
				}

			},

			//关闭弹窗
			close() {
				this.showPopup = false;
				uni.showTabBar({});
				//清空多单位 多自由项选择的值
				this.specsesText = []
				this.commonityDetailsId = ''
				//如果是多单位 或者 多单位且一个自由项
				if ((this.commonityItem?.isUnits == 1 && this.commonityItem?.isSpecs == 2) ||
					(this.commonityItem?.isUnits == 1 && this.commonityItem?.isSpecs == 1)) {
					this.commonityItem.defaultSKU = this.$store?.state?.skuInfo
				}
				//如果是多自由项 取多自由项的第一个重新赋值
				if (this.commonityItem.isSpecs == 1 && this.commonityItem.isUnits == 2) {
					this.commonityItem.defaultSKU = this.commonityItem.skuInfo[0];
					this.firstFreeArr = this.oldFirstFreeArr
					// console.log(this.oldFirstFreeArr)
					this.lastFreeArr = this.commonityItem.specses && this.commonityItem.specses.length == 2 ? this
						.commonityItem.specses[1].list.map(v => v.currentObj.optionName) : '';
					this.oldLastFreeArr = this.commonityItem.specses && this.commonityItem.specses.length == 2 ? this
						.commonityItem.specses[1].list.map(v => v.currentObj.optionName) : '';
					this.firstFreeName = this.lastFreeName = ``;
					this.commonityItem.specses.forEach(v => {
						v.list.forEach(a => {
							a.currentObj.checked = false;
						})
					})
				}
			}


		}
	}
</script>

<style lang="scss" scoped>
	.select_item {
		width: 100%;
		box-sizing: border-box;
		padding-bottom: 30rpx;

		.select_item_top {
			width: 100%;
			height: 168rpx;
			display: flex;

			.select_item_top_l {
				width: 200rpx;
				height: 200rpx;
				position: relative;

				image {
					width: 100%;
					height: 100%;
					position: absolute;
					top: -30rpx;
					left: 0;
					border-radius: 12rpx;
				}
			}

			.select_item_top_c {
				flex: 1;
				margin: 0 20rpx;

				.select_item_top_c_t {
					color: $text_color_333;
					font-size: $font_size_14;
				}

				.select_item_top_c_b {
					color: $text_color_808080;
					font-size: $font_size_12;

					.money {
						color: $text_color_ec4141;
						font-size: 32rpx;
						font-weight: bold;
					}
				}
			}

			.select_item_top_r {
				width: 40rpx;
				height: 40rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.select_item_list {
			overflow-y: auto;
			height: calc(65vh - 168rpx - 100rpx - 150rpx - 50rpx);

			.select_item_unit {
				width: 100%;
				height: 80rpx;
				display: flex;
				overflow-x: auto;
				line-height: 80rpx;
				border-bottom: 1px solid #f3f3f3;

				.select_item_unit_item {
					min-width: 160rpx;
					width: 160rpx;
					height: 100%;
					text-align: center;
					box-sizing: border-box;
				}

				.select_item_unit_item_active {
					border-bottom: 2px solid #ec4141 !important;
					color: #ec4141;
				}
			}

			.select_item_options {
				width: 100%;
				box-sizing: border-box;
				padding: 20rpx 0;

				.select_item_options_title {
					font-size: 32rpx;
					color: $text_color_333;
				}

				.select_item_options_item {
					display: flex;
					flex-wrap: wrap;
					gap: 10rpx;

					.select_item_options_item_l {
						// width: 110rpx;
						padding:0 20rpx;
						box-sizing: border-box;
						height: 64rpx;
						border-radius: $border_radius_4;
						background-color: #f3f3f3;
						font-size: $font_size_14;
						color: $text_color_333;
						text-align: center;
						line-height: 64rpx;
						margin-right: 20rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					.select_item_options_item_l_active {
						color: #FFF !important;
						background-color: #ec4141 !important;
						font-size: 28rpx;
						font-weight: bold;
					}
				}
			}
		}

		.select_item_num {
			width: 100%;
			height: 100rpx;
			margin-bottom: 20px;
			border-top: 1px solid #f3f3f3;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.select_item_num_l {
				font-size: 32rpx;
				color: #333;

				text {
					font-size: $font_size_14;
				}
			}
		}
	}

	.minus {
		width: 22px;
		height: 22px;
		border-width: 1px;
		border-color: #E6E6E6;
		border-style: solid;
		border-top-left-radius: 100px;
		border-top-right-radius: 100px;
		border-bottom-left-radius: 100px;
		border-bottom-right-radius: 100px;
		@include flex;
		justify-content: center;
		align-items: center;
		/deep/.u-icon__icon.uicon-minus {
							font-weight: bold !important;
							font-size: 28rpx !important;
						}
	}



	.plus {
		width: 22px;
		height: 22px;
		background-color: #FF0000;
		border-radius: 50%;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: center;
		align-items: center;
		/deep/.u-icon__icon.uicon-plus{
									font-weight: bold !important;
									font-size: 28rpx !important;
									
								}
	}

	/deep/.u-input {
		background-color: transparent !important;
		padding: 20rpx 16rpx !important;
	}
</style>